package com.gjintel.auction.business.dao.daoImpl;

import com.gjintel.auction.business.dao.IAuctionCompareBidDao;
import com.gjintel.auction.business.model.AuctionCompareBid;
import com.gjintel.sdk.base.dao.HibernateGenericDAO;
import com.gjintel.sdk.base.dao.Page;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/17.
 */
@Repository
public class AuctionCompareBidDaoImpl extends HibernateGenericDAO implements IAuctionCompareBidDao {
    @Override
    public List<AuctionCompareBid> findAllByAuctionIdAndBiddrId(String auctionId, String biddrId) {
        List<Object> params = new ArrayList<Object>();
        String hql = "from AuctionCompareBid acb where acb.auctionId = ? and acb.biddrId = ? order by acb.bidderTime desc";
        params.add(auctionId);
        params.add(biddrId);
        return this.find(hql, params.toArray());
    }

    @Override
    public List<AuctionCompareBid> findTopTenByAuctionId(String auctionId) {
        List<Object> params = new ArrayList<Object>();
        String hql = "from AuctionCompareBid acb where acb.auctionId = ? order by acb.bidderTime desc";
        params.add(auctionId);
        Page page = new Page();
        page.setPageNo(1);
        page.setPageSize(10);
        return this.findAsPage(hql, page, params.toArray());
    }

    @Override
    public int countAllByAuctionId(String auctionId) {
        List<Object> params = new ArrayList<Object>();
        String hql = "from AuctionCompareBid acb where acb.auctionId = ? order by acb.bidderTime desc";
        params.add(auctionId);
        return this.getHQLCount(hql, params.toArray());
    }

    @Override
    public int countDistinctByAuctionId(String auctionId) {
        List<Object> params = new ArrayList<Object>();
        String hql = "select count(distinct acb.biddrId) from AuctionCompareBid acb where acb.auctionId = ?";
        params.add(auctionId);
        return this.getHQLCountEx(hql, params.toArray());
    }
}